package my.data.x.dao;

import my.data.x.model.Job;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface JobMapper {
    @Results(id="config_long_varchar",value = @Result(property = "config",column = "config",jdbcType = JdbcType.LONGNVARCHAR))
    @Select("select id,name,schedule,start_mode,status,config from app.job")
    List<Job> selectJobs();
    @Insert("insert into app.job values(#{id},#{name},#{schedule},#{start_mode},#{status},#{config})")
    int insertJob(Job job);
    @Delete("delete from app.job where id=#{jobid}")
    int deleteJob(Long jobid);

    @ResultMap(value="config_long_varchar")
    @Select("select id,name,schedule,start_mode,status,config from app.job where id=#{jobid}")
    Job getJobById(long jobid);

    @Update("update app.job set status=#{status} where id=#{id}")
    int updateJobStatusById(Job job);

    @Select("select count(id) from app.job where name=#{name}")
    int selectJobFromName(String name);
    @Update("update app.job set config=#{config} where name=#{name}")
    int updateJob(Job job);

}
